package com.gec.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gec.model.system.ITripHotel;
import com.gec.model.system.ITripItinerary;
import com.gec.model.system.ITripItineraryOrder;
import com.gec.model.vo.ITripItineraryOrderVo;
import com.gec.system.mapper.ITripItineraryOrderMapper;
import com.gec.system.service.ITripItineraryOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gec.system.service.ITripItineraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author dafei
 * @since 2024-01-23
 */
@Service
public class ITripItineraryOrderServiceImpl extends ServiceImpl<ITripItineraryOrderMapper, ITripItineraryOrder> implements ITripItineraryOrderService {

    @Autowired
    private ITripItineraryService iTripItineraryService;

    @Override
    public IPage<ITripItineraryOrder> selectPage(IPage<ITripItineraryOrder> page1, ITripItineraryOrderVo iTripItineraryOrderVo) {
        IPage<ITripItineraryOrder> iPage = this.baseMapper.selectPage(page1, iTripItineraryOrderVo, null);
        return iPage;
    }




    @Override
    public void updateIsPaid(Long id, Integer isPaid) {
        ITripItineraryOrder it = baseMapper.selectById(id);
        it.setIsPaid(isPaid);
        baseMapper.update(it, null);

    }

    @Override
    public List<ITripItineraryOrder> getByIsPaid(Long isPaid) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("isPaid", isPaid);//相当于where name=1
        List<ITripItineraryOrder> list = baseMapper.selectList(wrapper);
        return list;
    }

    @Override
    public List<ITripItineraryOrder> getByNewDate(Long userId) {
        List<ITripItineraryOrder> it = baseMapper.getAllByUserId(userId);
        ArrayList<ITripItineraryOrder> list = new ArrayList<>();
//        QueryWrapper wrapper = new QueryWrapper();
//        wrapper.eq("userId",userId);//相当于where name=1
//        List<ITripItineraryOrder> it = baseMapper.selectList(wrapper);

        for (ITripItineraryOrder i : it) {
            ITripItinerary iti = iTripItineraryService.getById(i.getItineraryId());
            if (iti.getStartTime().after(new Date()) && i.getIsPaid() == 2) {
                list.add(i);
            }
        }
        return list;
    }

    @Override
    public List<ITripItineraryOrder> getByUserId(Long id) {
        List<ITripItineraryOrder> list = baseMapper.getAllByUserId(id);
        return list;
    }

}
